package com.example.mvvmkotlin

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.mvvmkotlin.databinding.ActivityFileBinding

class FileActivity : AppCompatActivity() {
    private lateinit var binding: ActivityFileBinding
    private val tool = Tool()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityFileBinding.inflate(layoutInflater)
        setContentView(binding.root)
        initView()
    }

    private fun initView() {

        //创建
        binding.btnCreate.setOnClickListener {
            tool.createFanganPath(this)
        }

        binding.btnSave.setOnClickListener{
            tool.writeConfig(tool.getFileRoot(this), "name", binding.tv1.text.toString(),"Name")
            tool.writeConfig(tool.getFileRoot(this), "num", binding.tv2.text.toString(),"Number")
        }

        binding.btnRead.setOnClickListener {
            val name = tool.readConfig(tool.getFileRoot(this), "name", "Name")
            val num = tool.readConfig(tool.getFileRoot(this), "num", "Number")
            binding.tv3.text = name
            binding.tv4.text = num
        }

    }
}